<%@ CODEPAGE=65001 %>
<%
'///////////////////////////////////////////////////////////////////////////////
'// 插件应用:    Z-Blog 1.8 Arwen
'// 插件制作:    haphic(http://haphic.esloy.com)
'// 备    注:    Couple 参数设定
'// 最后修改：   2009-12-29
'// 最后版本:    0.4
'///////////////////////////////////////////////////////////////////////////////
%>
<% Option Explicit %>
<% On Error Resume Next %>
<% Response.Charset="UTF-8" %>
<% Response.Buffer=True %>
<!-- #include file="../../../c_option.asp" -->
<!-- #include file="../../../function/c_function.asp" -->
<!-- #include file="../../../function/c_function_md5.asp" -->
<!-- #include file="../../../function/c_system_lib.asp" -->
<!-- #include file="../../../function/c_system_base.asp" -->
<!-- #include file="../../../function/c_system_plugin.asp" -->
<!-- #include file="../../../function/c_system_event.asp" -->
<!-- #include file="../../../plugin/p_config.asp" -->
<%
Call System_Initialize()

'检查非法链接
Call CheckReference("")

'检查权限
If BlogUser.Level>1 Then Call ShowError(6) 

'检查是否启用
If Not LCase(ZC_BLOG_THEME)=LCase("Couple") Then Call ShowError(48) 

Dim DataUpdete : DataUpdete=False

Dim strAct : strAct=Request.QueryString("act")
Dim strBuild : strBuild=Request.QueryString("bd")

If strAct=Empty And strBuild=Empty Then Call ShowError(3)

If strAct="Edit" Then

	Dim strFile : strFile=Request.QueryString("file")
	If strFile = "" Then Call ShowError(3)
	If InStr(strFile,".")>0 Then
		Dim tmpContent : tmpContent=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/INCLUDE/"&strFile,"utf-8")
		Dim strContent : strContent=Request.Form("strZC_File_Content")
		If strContent="" Then strContent=" "
		If tmpContent<>strContent Then
			Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/INCLUDE/"&strFile,strContent,"utf-8",False)
			DataUpdete = True
		End If
	End If

	If Err.Number=0 Then
		If DataUpdete = True Then
			If strBuild="t" Then
				Call SetBlogHint(Empty,Empty,True)
			Else
				'Call SetBlogHint(Empty,True,Empty)
				Call ClearGlobeCache
				Call LoadGlobeCache
			End If
			Call SetBlogHint_Custom("&raquo; 新数据已保存")
		Else
			Call SetBlogHint_Custom("&raquo; 提交的数据与原数据相同, 未作改变.")
		End If
	End If

ElseIf strAct="Lang" Then

	Dim strZC_Lang_ASP,strZC_Lang_JS
	Dim tmpZC_Lang_ASP,tmpZC_Lang_JS
	tmpZC_Lang_ASP=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/LANGUAGE/doc-asp.asp","utf-8")
	tmpZC_Lang_JS=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/LANGUAGE/doc-js.asp","utf-8")
	strZC_Lang_ASP=Request.Form("strZC_Lang_ASP")
	strZC_Lang_JS=Request.Form("strZC_Lang_JS")

	If Not strZC_Lang_ASP=Empty And strZC_Lang_ASP<>tmpZC_Lang_ASP Then
		Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/LANGUAGE/doc-asp.asp",strZC_Lang_ASP,"utf-8",False)
		DataUpdete = True
	End If
	If Not strZC_Lang_JS=Empty And strZC_Lang_JS<>tmpZC_Lang_JS Then
		Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/LANGUAGE/doc-js.asp",strZC_Lang_JS,"utf-8",False)
	End If

	If Err.Number=0 Then
		If DataUpdete = True Then
			Call SetBlogHint(Empty,Empty,True)
			Call SetBlogHint_Custom("&raquo; 新数据已保存")
		Else
			Call SetBlogHint_Custom("&raquo; 提交的数据与原数据相同, 或只更改了 .js 语言包, 无须重建.")
		End If
	End If

ElseIf strAct="Config" Then

	Dim tmpSng
	tmpSng=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/config.asp","utf-8")

	Dim strZC_Couple_UserLeft
	strZC_Couple_UserLeft=Request.Form("userLeft")
	If (Couple_MaleID<>CLng(strZC_Couple_UserLeft) Or Couple_MaleName<>Users(Clng(strZC_Couple_UserLeft)).Name) And Clng(strZC_Couple_UserLeft)>0 Then
		Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_MaleID",strZC_Couple_UserLeft)
		Call SaveValueForSetting(tmpSng,True,"String","Couple_MaleName",Users(Clng(strZC_Couple_UserLeft)).Name)
		Call SetBlogHint(Empty,Empty,True)
		DataUpdete = True
	End If

	Dim strZC_Couple_UserRight
	strZC_Couple_UserRight=Request.Form("userRight")
	If (Couple_FemaleID<>CLng(strZC_Couple_UserRight) Or Couple_FemaleName<>Users(Clng(strZC_Couple_UserRight)).Name) And Clng(strZC_Couple_UserRight)>0 Then
		Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_FemaleID",strZC_Couple_UserRight)
		Call SaveValueForSetting(tmpSng,True,"String","Couple_FemaleName",Users(Clng(strZC_Couple_UserRight)).Name)
		Call SetBlogHint(Empty,Empty,True)
		DataUpdete = True
	End If

	Dim tmpZC_Couple_HotPostDays
	If LoadValueForSetting(tmpSng,True,"Numeric","Couple_HotPostDays",tmpZC_Couple_HotPostDays) Then
		Dim strZC_Couple_HotPostDays
		strZC_Couple_HotPostDays=Request.Form("strZC_Couple_HotPostDays")
		If CLng(tmpZC_Couple_HotPostDays)<>CLng(strZC_Couple_HotPostDays) And Clng(strZC_Couple_HotPostDays)>0 Then
			Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_HotPostDays",strZC_Couple_HotPostDays)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_RandomDays
	If LoadValueForSetting(tmpSng,True,"Numeric","Couple_RandomDays",tmpZC_Couple_RandomDays) Then
		Dim strZC_Couple_RandomDays
		strZC_Couple_RandomDays=Request.Form("strZC_Couple_RandomDays")
		If CLng(tmpZC_Couple_RandomDays)<>CLng(strZC_Couple_RandomDays) And Clng(strZC_Couple_RandomDays)>0 Then
			Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_RandomDays",strZC_Couple_RandomDays)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_AutoBuildInterval
	If LoadValueForSetting(tmpSng,True,"Numeric","Couple_AutoBuildInterval",tmpZC_Couple_AutoBuildInterval) Then
		Dim strZC_Couple_AutoBuildInterval
		strZC_Couple_AutoBuildInterval=Request.Form("strZC_Couple_AutoBuildInterval")
		If CLng(tmpZC_Couple_AutoBuildInterval)<>CLng(strZC_Couple_AutoBuildInterval) And Clng(strZC_Couple_AutoBuildInterval)>0 Then
			Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_AutoBuildInterval",strZC_Couple_AutoBuildInterval)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_TagsCount
	If LoadValueForSetting(tmpSng,True,"Numeric","Couple_TagsCount",tmpZC_Couple_TagsCount) Then
		Dim strZC_Couple_TagsCount
		strZC_Couple_TagsCount=Request.Form("strZC_Couple_TagsCount")
		If CLng(tmpZC_Couple_TagsCount)<>CLng(strZC_Couple_TagsCount) And Clng(strZC_Couple_TagsCount)>0 Then
			Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_TagsCount",strZC_Couple_TagsCount)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_TagsFilter
	If LoadValueForSetting(tmpSng,True,"Numeric","Couple_TagsFilter",tmpZC_Couple_TagsFilter) Then
		Dim strZC_Couple_TagsFilter
		strZC_Couple_TagsFilter=Request.Form("strZC_Couple_TagsFilter")
		If CLng(tmpZC_Couple_TagsFilter)<>CLng(strZC_Couple_TagsFilter) And Clng(strZC_Couple_TagsFilter)>=0 Then
			Call SaveValueForSetting(tmpSng,True,"Numeric","Couple_TagsFilter",strZC_Couple_TagsFilter)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_HotPostOrder
	If LoadValueForSetting(tmpSng,True,"String","Couple_HotPostOrder",tmpZC_Couple_HotPostOrder) Then
		Dim strZC_Couple_HotPostOrder
		strZC_Couple_HotPostOrder=Request.Form("strZC_Couple_HotPostOrder")
		If tmpZC_Couple_HotPostOrder<>strZC_Couple_HotPostOrder And Len(strZC_Couple_HotPostOrder)>0 Then
			Call SaveValueForSetting(tmpSng,True,"String","Couple_HotPostOrder",strZC_Couple_HotPostOrder)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_TagsOrder
	If LoadValueForSetting(tmpSng,True,"String","Couple_TagsOrder",tmpZC_Couple_TagsOrder) Then
		Dim strZC_Couple_TagsOrder
		strZC_Couple_TagsOrder=Request.Form("strZC_Couple_TagsOrder")
		If tmpZC_Couple_TagsOrder<>strZC_Couple_TagsOrder And Len(strZC_Couple_TagsOrder)>0 Then
			Call SaveValueForSetting(tmpSng,True,"String","Couple_TagsOrder",strZC_Couple_TagsOrder)
			DataUpdete = True
		End If
	End If

	Dim tmpZC_Couple_RegHost
	If LoadValueForSetting(tmpSng,True,"String","Couple_RegHost",tmpZC_Couple_RegHost) Then
		Dim strZC_Couple_RegHost
		strZC_Couple_RegHost=Request.Form("strZC_Couple_RegHost")
		If tmpZC_Couple_RegHost<>strZC_Couple_RegHost And Len(strZC_Couple_RegHost)>0 Then
			Call SaveValueForSetting(tmpSng,True,"String","Couple_RegHost",strZC_Couple_RegHost)
			DataUpdete = True
		End If
	End If

	Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/config.asp",tmpSng,"utf-8",False)

	If Err.Number=0 Then
		If DataUpdete = True Then
			Call SetBlogHint(Empty,True,Empty)
			Call SetBlogHint_Custom("&raquo; 新数据已保存")
		Else
			Call SetBlogHint_Custom("&raquo; 提交的数据与原数据相同, 未作改变.")
		End If
	End If

ElseIf strAct="Clear" Then

	Call Couple_ClearCaches()

	Call SetBlogHint_Custom("&raquo; 缓存文件已清空.")

ElseIf strAct="TrackBack" Then
	Dim strTemplateDefault : strTemplateDefault=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/"&ZC_TEMPLATE_DIRECTORY&"/default.html","utf-8")
	If Not IsEmpty(Request.QueryString("CS")) Then
		strTemplateDefault=Replace(strTemplateDefault,"<#ZC_DPMSG017#>","<#ZC_DPMSG018#>")
		strTemplateDefault=Replace(strTemplateDefault,"<#CACHE_INCLUDE_TRACKBACKS#>","<#CACHE_INCLUDE_CMTSTAR#>")
	End If
	If Not IsEmpty(Request.QueryString("TB")) Then
		strTemplateDefault=Replace(strTemplateDefault,"<#ZC_DPMSG018#>","<#ZC_DPMSG017#>")
		strTemplateDefault=Replace(strTemplateDefault,"<#CACHE_INCLUDE_CMTSTAR#>","<#CACHE_INCLUDE_TRACKBACKS#>")
	End If
	Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/"&ZC_TEMPLATE_DIRECTORY&"/default.html",strTemplateDefault,"utf-8",False)

	If Err.Number=0 Then
		Call SetBlogHint(Empty,True,Empty)
		Call SetBlogHint_Custom("&raquo; 新设置已生效. <a href="""&ZC_BLOG_HOST&""" target=""_blank"">请返回首页查看</a>.")
	End If
End If

Response.Redirect "setting.asp"


Call System_Terminate()

If Err.Number<>0 then
  Call ShowError(0)
End If
%>